Seata
Seata 是一款开源的分布式事务解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务。
如何使用
- 下载运行Nacos。
- 下载Seata压缩包。
- 修改conf/registry配置。进去一看便知。
- 默认是文件存储,也不要改了,直接运行吧。
- 各个服务都必须有表:undo_log 1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14CREATE TABLE `undo_log` ( 
 `id` bigint(20) NOT NULL AUTO_INCREMENT,
 `branch_id` bigint(20) NOT NULL,
 `xid` varchar(100) NOT NULL,
 `context` varchar(128) NOT NULL,
 `rollback_info` longblob NOT NULL,
 `log_status` int(11) NOT NULL,
 `log_created` datetime NOT NULL,
 `log_modified` datetime NOT NULL,
 `ext` varchar(100) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `ux_undo_log` (`xid`,`branch_id`)
 ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
- SqlSessionFactoryBean中使用Seata代理的数据源。 1 
 2
 3public DataSourceProxy getDataSourceProxy() { 
 return new DataSourceProxy(dataSource);
 }
- registry.conf
| 1 | registry { | 
- file.conf1 
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33service { 
 #transaction service group mapping
 vgroupMapping.my_test_tx_group = "default"
 #only support when registry.type=file, please don't set multiple addresses
 default.grouplist = "127.0.0.1:8091"
 #degrade, current not support
 enableDegrade = false
 #disable seata
 disableGlobalTransaction = false
 }
 ## transaction log store, only used in seata-server
 store {
 ## store mode: file、db、redis
 mode = "file"
 ## file store property
 file {
 ## store location dir
 dir = "sessionStore"
 # branch session size , if exceeded first try compress lockkey, still exceeded throws exceptions
 maxBranchSessionSize = 16384
 # globe session size , if exceeded throws exceptions
 maxGlobalSessionSize = 512
 # file buffer size , if exceeded allocate new buffer
 fileWriteBufferCacheSize = 16384
 # when recover batch read size
 sessionReloadReadSize = 100
 # async, sync
 flushDiskMode = async
 }
 }
